package com.etone.smartAudit.controller;

import com.etone.smartAudit.service.AdminLogService;
import com.etone.smartAudit.vo.PagerVO;
import com.etone.smartAudit.vo.adminLog.AdminLogVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * @author: 蒋学伟
 * @create: 2020-06-16 09:49:19
 * @Description AdminLogController
 */
@AllArgsConstructor
@RestController
@Api(tags = "日志", value = "AdminLogController")
public class AdminLogController {
    private AdminLogService adminLogService;

    @ApiOperation(value = "日志列表《完》")
    @GetMapping("/adminLogs")
    public PagerVO<AdminLogVO> list(
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "用户名称") @RequestParam(required = false) String adminNickName,
            @ApiParam(value = "操作开始时间") @RequestParam(required = false) Date startCreateTime,
            @ApiParam(value = "操作结束时间") @RequestParam(required = false) Date endCreateTime,
            @ApiParam(value = "操作类型") @RequestParam(required = false) String module,
            @ApiParam(value = "操作动作") @RequestParam(required = false) String item
    ) {

        return adminLogService.list(adminNickName, startCreateTime, endCreateTime, module, item, page, pageSize);
    }

    @ApiOperation(value = "操作类型列表《完》")
    @GetMapping("/adminLogs/modules")
    public List<String> listModules() {
        return adminLogService.listModules();
    }

    @ApiOperation(value = "操作动作列表《完》")
    @GetMapping("/adminLogs/modules/items")
    public List<String> listItems(
            @ApiParam(value = "操作类型") @RequestParam(required = false) String module
    ) {
        return adminLogService.listItems(module);
    }

    @ApiOperation(value = "日志导出《完》")
    @GetMapping("/adminLogs/export")
    public void export(
            @ApiParam(value = "用户名称") @RequestParam(required = false) String adminNickName,
            @ApiParam(value = "操作开始时间") @RequestParam(required = false) Date startCreateTime,
            @ApiParam(value = "操作结束时间") @RequestParam(required = false) Date endCreateTime,
            @ApiParam(value = "操作类型") @RequestParam(required = false) String module,
            @ApiParam(value = "操作动作") @RequestParam(required = false) String item,
            HttpServletResponse response
    ) {
        adminLogService.export(adminNickName, startCreateTime, endCreateTime, module, item, response);
    }
}
